<?php
/**
 * Hello Model for Hello World Component
 *
 * @package    Joomla.Tutorials
 * @subpackage Components
 * @link http://dev.joomla.org/component/option,com_jd-wiki/Itemid,31/id,tutorials:modules/
 * @license    GNU/GPL
 */

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();

jimport( 'joomla.application.component.model' );
require_once 'contact.php';
/**
 * Hello Model
 *
 * @package    Joomla.Tutorials
 * @subpackage Components
 */
class HelloModelHello extends JModel
{
	/**
	 * Gets the greeting
	 * @return string The greeting to be displayed to the user
	 */
	function getGreeting($time = null)
	{	
		if($time < 12)
		return 'Good morning!';
		if($time > 12 && $time < 17)
		return 'Good afternoon!';
		if($time > 17)
		return 'Good evening!';
	}

	function getContacts()
	{		
		$contactList = new ArrayObject(); 
		$db =& JFactory::getDBO();
		$query = 'SELECT * FROM #__my_contacts';
		$db->setQuery( $query );
		$rs = $db->loadObjectList();
		foreach($rs as &$row){
			$contact = new Contact();
			
			$contact->firstName = $row->first_name;
			$contact->lastName = $row->last_name;
			$contact->email = $row->email;
			$contact->phone = $row->phone;
			
			$contactList->append($contact);
		}
		return $contactList;
	}

}